#include "arduino.h"
#include <QDebug>

using namespace Aurasim;
Arduino::Arduino(QObject *parent) : QObject(parent),
    isRunning(false)
{
    mPid = new qint64(10000);
    for(int i = 0; i < MAX_PIN_LENGTH; i++) {
        mAnaVals.append(0);
        mDigVals.append(0);
        mPinMods.append(0);
        mpinRWs.append(0);
        mPinVals.append(0);
        mSignalTypes.append(0);
    }
}

Arduino::~Arduino()
{
    isRunning = false;
}

bool Arduino::isSimulating() const
{
    return isRunning;
}

void Arduino::tick(const int &msec)
{
    if(!isRunning)
        return;

    for(int i = 0; i < jservuno::MAX_PINS; i++) {
        mDigVals[i] = jservuno::board()->digVal(i);
        mAnaVals[i] = jservuno::board()->anaVal(i);
        mPinVals[i] = mDigVals[i] | mAnaVals[i];
        mPinMods[i] = jservuno::board()->pinMode(i);
        mSignalTypes[i] = jservuno::board()->signalType(i);
    }
}

void Arduino::start()
{
    jservuno::board()->startSim();
    isRunning = true;
}

void Arduino::stop()
{
    isRunning = false;
    jservuno::board()->stopSim();
}
